import $api from '@/api'

export default {
	/* 首页 */
	index (options, url) {
		return new Promise((resolve, reject) => {
			$api.index(options, url).then(res => {
				resolve(res)
			})
		})
	},

  getData (url, options) {
    return new Promise((resolve, reject) => {
      $api.getData(url, options).then(res => {
        resolve(res)
      })
    })
  },

  postData (options, url) {
    return new Promise((resolve, reject) => {
      $api.postData(options, url).then(res => {
        resolve(res)
      })
    })
  },

	/* 维护类 */
	safeguard (options) {
		return new Promise((resolve, reject) => {
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					radio_equipment_online_rate,
					radio_equipment_availability,
					indoor_load_efficiency
				] = [[], [], []]
				let a = bean.pop()
				a.radio_equipment_online_rate.forEach(item => {
					let key
					if (options.dimensionType == 0) {
						key = options.area ? item.city : item.area
						if (key == '不详') {
							return
						}
					} else if (options.dimensionType == 1) {
						key = item.starttime
					}

					radio_equipment_online_rate.push({
						name: '无线设备在网率',
						key,
						value: item.radio_equipment_online_rate
					})
				})
				bean.forEach(item => {
					let key
					if (options.dimensionType == 0) {
						// 地理纬度
						key = options.area ? item.city : item.area
						if (key == '不详') {
							return
						}
					} else if (options.dimensionType == 1) {
						// 时间纬度
						key = item.starttime
					}
					/* radio_equipment_online_rate.push({
						name: '无线设备在网率',
						key,
						value: item.radio_equipment_online_rate
					}) */
					radio_equipment_availability.push({
						name: '无线设备可用率',
						key,
						value: item.radio_equipment_availability
					})
					indoor_load_efficiency.push({
						name: '室分承载效率',
						key,
						value: item.indoor_load_efficiency
					})
				})

				if (options.dimensionType == 0) {
					radio_equipment_online_rate.sort(function (a, b) { return b.value - a.value })
					radio_equipment_availability.sort(function (a, b) { return b.value - a.value })
					indoor_load_efficiency.sort(function (a, b) { return b.value - a.value })
				}
				resolve({
					radio_equipment_online_rate,
					radio_equipment_availability,
					indoor_load_efficiency
				})
			})
		})
	},
	/* 投诉类 */
	complaint (options) {
		return new Promise((resolve, reject) => {
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					basic_comm_complain_ratio,
					re_complaints_rate,
					Complaint_sat_rate
				] = [[], [], []]
				bean.forEach(item => {
					let key
					if (options.dimensionType == 0) {
						// 地理纬度
						key = options.area ? item.city : item.area
						if (key == '不详') {
							return
						}
					} else if (options.dimensionType == 1) {
						// 时间纬度
						key = item.starttime
					}
					basic_comm_complain_ratio.push({
						name: '万投比',
						key,
						value1: item.complaint_source_num,
						value2: item.basic_comm_complain_ratio
					})
					re_complaints_rate.push({
						name: '重复投诉率',
						key,
						value: item.complain_repeat_rate
					})
					Complaint_sat_rate.push({
						name: '投诉回访满意率',
						key,
						value: item.return_visit_sat_rate_range
					})
				})
				if (options.dimensionType == 0) {
					basic_comm_complain_ratio.sort(function (a, b) { return b.value - a.value })
					re_complaints_rate.sort(function (a, b) { return b.value - a.value })
					Complaint_sat_rate.sort(function (a, b) { return b.value - a.value })
				}
				resolve({
					basic_comm_complain_ratio,
					re_complaints_rate,
					Complaint_sat_rate
				})
			})
		})
	},
	/* 优化类 */
	optimize (options) {
		return new Promise((resolve, reject) => {
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					one,
					bad_cell_num_ratio,
					two_l_two_h_cell_ratio
				] = [[], [], []]
				bean.forEach(item => {
					let key
					if (options.dimensionType == 0) {
						// 地理纬度
						key = options.area ? item.city : item.area
						if (key == '不详') {
							return
						}
					} else if (options.dimensionType == 1) {
						// 时间纬度
						key = item.starttime
					}
					one.push({
						key,
						value1: item.wireless_access_rate,
						value2: item.wireless_dropcall_rate
					})
					bad_cell_num_ratio.push({
						name: '劣化小区占比',
						key,
						value: item.bad_cell_num_ratio
					})
					two_l_two_h_cell_ratio.push({
						name: 'volte两低两高小区占比',
						key,
						value: item.two_l_two_h_cell_ratio
					})
				})
				if (options.dimensionType == 0) {
					one.sort(function (a, b) { return b.value1 - a.value1 })
					bad_cell_num_ratio.sort(function (a, b) { return b.value - a.value })
					two_l_two_h_cell_ratio.sort(function (a, b) { return b.value - a.value })
				}
				resolve({
					one,
					bad_cell_num_ratio,
					two_l_two_h_cell_ratio
				})
			})
		})
	},

	/* 制式/站型 */
	type (options, flag) {
		return new Promise((resolve, reject) => {
			if (flag == '行政属性') {
				options.conditionType = '5'
			}
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					one,
					single_cell_upoct,
					radio_use_rate,
					three,
					four
				] = [[], [], [], [], []]
				if (flag) {
					bean.forEach(item => {
						let name
						if (flag == '制式') {
							name = item.pattern
						} else if (flag == '站型') {
							name = item.site_type
						} else if (flag == '行政属性') {
							name = item.adm_pro
						} else if (flag == '频段显示') {
							name = item.fre_band
						}
						let key
						if (name == '全量小区' || name == '不详') {
							return
						}
						if (options.dimensionType == 0) {
							// 地理纬度
							key = options.area ? item.city : item.area
							if (key == '不详') {
								return
							}
						} else if (options.dimensionType == 1) {
							key = item.starttime
						}

						one.push({
							name: '流量' + name,
							key,
							value: item.upoct
						}, {
							name: '话务量' + name,
							key,
							value: item.volte_voice_traffic
						})
						single_cell_upoct.push({
							name,
							key,
							value: item.single_cell_upoct
						})
						radio_use_rate.push({
							name,
							key,
							value: item.radio_use_rate
						})
						three.push({
							name,
							key,
							value: item.high_load_num
						})
						four.push({
							name,
							key,
							value: item.high_load_num_shengnei
						})
					})
				} else {
					bean.forEach(item => {
						let key
						if (options.dimensionType == 0) {
							// 地理纬度
							key = options.area ? item.city : item.area
							if (key == '不详') {
								return
							}
						} else if (options.dimensionType == 1) {
							// 时间纬度
							key = item.starttime
						}
						one.push({
							key,
							value1: item.upoct,
							value2: item.volte_voice_traffic
						})
						single_cell_upoct.push({
							name: '单小区流量',
							key,
							value: item.single_cell_upoct
						})
						radio_use_rate.push({
							name: '无线利用率',
							key,
							value: item.radio_use_rate
						})
						three.push({
							key,
							value1: item.high_load_num,
							value2: item.high_load_ratio
						})
						four.push({
							name,
							key,
							value1: item.high_load_num_shengnei,
							value2: item.bad_cell_num_ratio_shengnei
						})
					})
				}
				resolve({
					one,
					single_cell_upoct,
					radio_use_rate,
					three,
					four
				})
			})
		})
	},
	/* 分場景 */
	async querySceneNames () {
		let sceneNames = []
		let querySceneNames = await $api.querySceneNames()
		querySceneNames.forEach(item => {
			sceneNames.push(item.scene_name)
		})
		return sceneNames
	},
	async scene (options) {
		let getMsg = await $api.getMsg(options)
		let bean = getMsg.bean
		let [
			one,
			radio_use_rate,
			three,
			four
		] = [[], [], [], []]

		bean.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			one.push({
				name: item.scene_name + '流量',
				key,
				value: item.upoct
			}, {
				name: item.scene_name + '话务量',
				key,
				value: item.volte_voice_traffic
			})
			radio_use_rate.push({
				name: item.scene_name,
				key,
				value: item.radio_use_rate
			})
			three.push({
				name: item.scene_name,
				key,
				value: item.high_load_num
			})
			four.push({
				name: item.scene_name,
				key,
				value: item.high_load_num_shengnei
			})
		})
		return {
			one,
			radio_use_rate,
			three,
			four
		}
	},
	/* 场景对比 */
	contrast (options) {
		return new Promise((resolve, reject) => {
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					one,
					radio_use_rate,
					three,
					four
				] = [[], [], [], []]

				bean.forEach(item => {
					let key = item.scene_name
					if (key == '全量小区' || key == '不详') {
						return
					}
					one.push({
						key,
						value1: item.upoct,
						value2: item.volte_voice_traffic
					})
					radio_use_rate.push({
						name: '无线利用率',
						key,
						value: item.radio_use_rate
					})
					three.push({
						key,
						value1: item.high_load_num,
						value2: item.high_load_ratio
					})
					four.push({
						key,
						value1: item.high_load_num_shengnei,
						value2: item.bad_cell_num_ratio_shengnei
					})
				})
				resolve({
					one,
					radio_use_rate,
					three,
					four
				})
			})
		})
	},
	/* 高铁分线路 */
	train (options) {
		return new Promise((resolve, reject) => {
			$api.getMsg(options).then(res => {
				let bean = res.bean
				let [
					upoct,
					volte_voice_traffic,
					radio_use_rate,
					three,
					four
				] = [[], [], [], [], []]

				bean.forEach(item => {
					let key
					let name = ''
					if (options.dimensionType == 0) {
						// 地理纬度
						name = item.high_speed_railway
						key = options.area ? item.city : item.area
						if (key == '不详') {
							return
						}
					} else if (options.dimensionType == 1) {
						if (options.high_speed_railway == '!全量小区') {
							key = item.high_speed_railway
						} else {
							name = item.high_speed_railway
							key = item.starttime
						}
					}
					if (key == '全量小区' || key == '不详') {
						return
					}
					upoct.push({
						name: name || '流量',
						key,
						value: item.upoct
					})
					volte_voice_traffic.push({
						name: name || '话务量',
						key,
						value: item.volte_voice_traffic
					})
					radio_use_rate.push({
						name: name || '无线利用率',
						key,
						value: item.radio_use_rate
					})
					if (options.high_speed_railway == '!全量小区' || options.high_speed_railway.split(',').length == 1) {
						three.push({
							key,
							value1: item.high_load_num,
							value2: item.high_load_ratio
						})
						four.push({
							key,
							value1: item.high_load_num_shengnei,
							value2: item.bad_cell_num_ratio_shengnei
						})
					} else {
						three.push({
							name,
							key,
							value: item.high_load_num
						})
						four.push({
							name,
							key,
							value: item.high_load_num_shengnei
						})
					}
				})
				resolve({
					upoct,
					volte_voice_traffic,
					radio_use_rate,
					three,
					four
				})
			})
		})
	},
	/* 资源类 */
	async resource (options, flag) {
		let one = await $api.getMsg(options)
		options.pattern = '!全量小区'
		options.site_type = '全量小区'
		options.fre_band = '全量小区'
		let other = await $api.getMsg(options)
		let bean1 = one.bean
		let bean2 = other.bean

		let [
			lte,
			FDD1800,
			FDD900,
			TDD
		] = [[], [], [], []]
		let name
		let str = ''
		if (flag == '分频段') {
			name = 'fre_band'
			str = '频段'
		} else if (flag == '分站型') {
			name = 'site_type'
			// str = '站型'
		}
		bean1.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
				if (key == '不详') {
					return
				}
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			if (flag == '全量') {
				lte.push({
					name: '',
					key,
					value1: item.site_num_lte_lte,
					value2: item.cell_num_lte_lte
				})
			} else {
				if (item[name] == '不详') {
					return
				}
				lte.push({
					name: item[name] + str,
					name1: item[name] + '基站',
					name2: item[name] + '小区',
					key,
					value1: item.site_num_lte_lte,
					value2: item.cell_num_lte_lte
				})
			}
		})

		bean2.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
				if (key == '不详') {
					return
				}
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			if (item.pattern == 'FDD1800') {
				FDD1800.push({
					key,
					value1: item.site_num_lte_lte,
					value2: item.cell_num_lte_lte
				})
			} else if (item.pattern == 'FDD900') {
				FDD900.push({
					key,
					value1: item.site_num_lte_lte,
					value2: item.cell_num_lte_lte
				})
			} else if (item.pattern == 'TDD') {
				TDD.push({
					key,
					value1: item.site_num_lte_lte,
					value2: item.cell_num_lte_lte
				})
			}
		})
		return {
			lte,
			FDD1800,
			FDD900,
			TDD
		}
	},
	/* 干扰类 */
	async disturb (options) {
		options.pattern = '全量小区'
		let result1 = await $api.getMsg(options)
		let bean1 = result1.bean
		options.pattern = ''
		let result2 = await $api.getMsg(options)
		let bean2 = result2.bean
		let [
			all,
			TDD,
			Fdd
		] = [[], [], []]
		let [arr1, arr2] = [[], []]
		bean1.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
				if (key == '不详') {
					return
				}
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			all.push({
				key,
				value1: item.hige_interfere_num,
				value2: item.hige_interfere_rate
			})
		})
		bean2.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
				if (key == '不详') {
					return
				}
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			if (item.pattern == 'TDD') {
				TDD.push({
					key,
					value1: item.hige_interfere_num,
					value2: item.hige_interfere_rate
				})
			} else if (item.pattern == 'FDD1800') {
				arr1.push({
					key,
					name: 'FDD1800',
					value1: item.hige_interfere_num,
					value2: item.hige_interfere_rate
				})
			} else if (item.pattern == 'FDD900') {
				arr2.push({
					key,
					name: 'FDD900',
					value1: item.hige_interfere_num,
					value2: item.hige_interfere_rate
				})
			}
		})
		Fdd = [...arr1, ...arr2]
		return {
			all,
			TDD,
			Fdd
		}
	},

	async coverlat (options, flag) {
		let scene_class = options.scene_class
		options.scene_class = '全量小区'
		let getMsg1
		let bean1
		if (options.adm_pro == '!全量小区') {
			options.conditionType = '5'
			getMsg1 = await $api.getMsg(options)
			bean1 = getMsg1.bean
		} else {
			options.conditionType = '0'
			getMsg1 = await $api.getMsg(options)
			bean1 = getMsg1.bean
		}

		options.conditionType = '1'
		options.scene_class = scene_class
		options.pattern = '全量小区'
		options.site_type = '全量小区'
		options.adm_pro = '全量小区'
		let getMsg3 = await $api.getMsg(options)
		let bean3 = getMsg3.bean

		delete options.conditionType
		delete options.scene_class
		let getMsg2 = await $api.getMsg(options)
		let bean2 = getMsg2.bean


		let [
			one,
			two,
			three,
			oneFilter,
			threeFilter
		] = [[], [], [], [], []]

		bean1.forEach(item => {
			let name
			if (flag == '站型') {
				name = item.site_type
			} else if (flag == '制式') {
				name = item.pattern
			} else if (flag == '行政属性') {
				name = item.adm_pro
				// name = '';
			}
			if (name == '全量小区' || name == '不详') {
				return
			}
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			oneFilter.push(`${name}MR覆盖率(%)`)
			one.push({
				name: `${name}MR覆盖率(%)`,
				key,
				value: item.rsrp_cover_rate
			}, {
				name: `${name}弱覆盖小区占比(%)`,
				key,
				value: item.rsrp_lt_f110_cell_rate
			})
		})

		bean2.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			two.push({
				key,
				value1: item.rsrp_cover_rate,
				value2: item.rsrp_lt_f110_cell_rate
			})
		})
		bean3.forEach(item => {
			let key
			if (options.dimensionType == 0) {
				// 地理纬度
				key = options.area ? item.city : item.area
			} else if (options.dimensionType == 1) {
				// 时间纬度
				key = item.starttime
			}
			threeFilter.push(item.scene_name + 'MR覆盖率(%)')
			three.push({
				name: item.scene_name + 'MR覆盖率(%)',
				key,
				value: item.rsrp_cover_rate
			}, {
				name: item.scene_name + '弱覆盖小区占比(%)',
				key,
				value: item.rsrp_lt_f110_cell_rate
			})
		})
		return {
			one,
			two,
			three,
			oneFilter,
			threeFilter
		}
	},

	async covercontrast (options) {
		let getMsg = await $api.getMsg(options)
		let bean = getMsg.bean
		let [
			one,
			two
		] = [[], []]

		bean.forEach(item => {
			let key = item.scene_name
			if (key == '全量小区' || key == '不详') {
				return
			}
			one.push({
				name: '覆盖率',
				key,
				value: item.rsrp_cover_rate
			})
			two.push({
				name: '弱覆盖小区占比',
				key,
				value: item.rsrp_lt_f110_cell_rate
			})
		})
		return {
			one,
			two
		}
	},

	/* 保障日报 */
	// 获取列表
	getEnsureDailyList (options) {
		return $api.getEnsureDailyList(options)
	},
	// 下载
	getEnsureDailyInfo (path) {
		$api.getEnsureDailyInfo(path)
	}
}
